package com.adam.mbt.controller;

import com.adam.mbt.entity.User;
import com.adam.mbt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/selectAllUser")
    public List<User> selectAllUser(){
        return userService.selectAllUser();
    }

    @GetMapping("/getUserByMap")
    public List<User> getUserByMap(@RequestParam(value = "userId", required = true) Integer userId,
                                   @RequestParam(value = "userName", required = true) String userName){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("userName",userName);
        return userService.getUserByMap(map);
    }


    @GetMapping("/{userId}")
    public User selectByPrimaryKey(@PathVariable("userId") Integer userId){
        return userService.selectByPrimaryKey(userId);
    }

    @GetMapping("/findUserByIdAndUserName")
    public User findUserByIdAndUserName(@RequestParam(value = "userId", required = true) Integer userId,
                                        @RequestParam(value = "userName", required = true) String userName){
        return userService.findUserByIdAndUserName(userId,userName);
    }

    @GetMapping("/getUserByBean")
    public List<User> getUserByBean(@RequestParam(value = "userId", required = true) Integer userId,
                                        @RequestParam(value = "userName", required = true) String userName){
        return userService.getUserByBean(userId,userName);
    }

}
